package keer.httpinterface.proxy;

import keer.httpinterface.http.HttpBody;
import keer.httpinterface.http.HttpContentType;
import keer.httpinterface.http.HttpRequest;
import keer.httpinterface.http.HttpParams;

/**
 * 带请求体的http请求配置实现，使用{@link ContentTypeBodyReader#read(HttpContentType, HttpParams)}方法创建请求体，
 * 并且将请求体添加到{@link HttpRequest}实例中返回。
 * @see ContentTypeBodyReader
 * @see HttpRequest
 *
 * @author Keer
 * @since 1.0.0
 */
public class ContentBodyRequestAnnotationConfigure extends HttpRequestAnnotationConfigure {
    @Override
    protected final HttpRequest configure(ConfigureContext context) throws Exception {
        HttpBody body = ContentTypeBodyReader.read(context.getContentType(), context.getParams());
        HttpRequest request = HttpRequest.create(context.getUrl(), context.getMethod(), body);
//        request.setHeader(HttpRequest.CONTENT_TYPE, context.getContentType().contentType());
        request.getHeaders().setContentType(body.getContentType());
        return request;
    }

}
